package com.itheima.anli2;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class JunitTest {

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
        //模拟junit去执行所有单元测试方法：

        //1.获取测试类Class对象
        Class<CatTest> aClass = CatTest.class;


        //2.获取测试类中所有的测试方法Method对象
        Method[] declaredMethods = aClass.getDeclaredMethods();


        //3.判断方法上·是否有Mytest对象
        for (Method declaredMethod : declaredMethods) {
            if (declaredMethod.isAnnotationPresent(Mytest.class)){
                declaredMethod.invoke(aClass.newInstance());
            }
        }
        //如果有，执行反射执行此方法，进行测试
    }
}
